<template>
	<view class="content">
		<view class="bannerBG">
			 <view :class="current == 1 ? 'active' : 'inactive'" @tap="changCurrent(1)">满算力矿机</view>
		     <view :class="current == 3 ? 'active' : 'inactive'" @tap="changCurrent(3)">独享矿机</view>
	         <view :class="current == 2 ? 'active' : 'inactive'" @tap="changCurrent(2)">存质押币</view>
		</view>
		
		<view @tap="toDetail(item)" class="listItem" v-for="(item, itemIndex) in listData" :key="itemIndex">
			<view class="itemTitle">
				<view style="display: flex;">
					<image style="width: 40upx;height: 40upx;" src="../../static/product/itemheader.png" mode="scaleToFill"></image>
					<text style="font-size: $uni-font-size-sm;color: #433302;margin-left: 20upx;">{{item.name}}</text>
				</view>
				<view style="display: flex;flex-direction: column;justify-content: center;">
					<!-- <text style="font-size: 18upx;color: #656565;">是否有效</text> -->
					<text style="font-size: 18upx;color: #656565;">{{item.valid==1?'有效':'无效'}}</text>
				</view>
			</view>
			<view v-if="current!=3" style="display: flex;justify-content: space-between;align-items: center;margin-top: 40upx;">
				<text style="font-size: 30upx;color: #656565;">矿工算力</text>
				<text style="font-size: 30upx;color: #656565;">{{item.computePower}}</text>
			</view>
			<view v-if="current==3" style="display: flex;justify-content: space-between;align-items: center;margin-top: 40upx;">
				<text style="font-size: 30upx;color: #656565;">年化率</text>
				<text style="font-size: 30upx;color: #656565;">{{item.nhl}}%</text>
			</view>
			<view v-if="current!=3"  style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">需要支付</text>
				<text style="font-size: 30upx;color: #FB9C28;">{{item.usdt}}USDT/{{item.fil}}FIL</text>
			</view>
			<view style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">合约周期</text>
				<text style="font-size: 30upx;color: #656565;">{{item.hyzq}}天</text>
			</view>
			<view v-if="current!=3"  style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">剩余矿机</text>
				<text style="font-size: 30upx;color: #656565;">{{item.kjNum}}份</text>
			</view>
			<view v-if="current!=3"  style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">服务费率</text>
				<text style="font-size: 30upx;color: #656565;">{{item.fee}}%</text>
			</view>
			<view v-if="current!=3"  style="width: 100%;height: 4upx;background-color: #dddddd;margin-top: 30upx;"></view>
			<view v-if="current!=3"  style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">封存周期</text>
				<text style="font-size: 30upx;color: #656565;">{{item.fczq}}天</text>
			</view>
		</view>
		
	</view>
</template>

<script>
	
	export default {
		components: {
			
		},
		data() {
			return {
				token:'',
				current:1,
				listData: []
			}
		},
		onLoad() {
	
		},
		onShow(){
			var that=this;
			that.checkToken()
		},
		methods: {
			changCurrent:function(page){
				var that = this;
				that.current = page;
				that.getFilList(that.token);
			},
			toDetail:function(item){
				var that = this;
				uni.navigateTo({
					url:"productDetail?id="+item.id+"&current="+that.current
				})
			},
			checkToken(){
				var that=this;
				 uni.getStorage({
				    key: 'token',
				    success: function (res) {
						that.token=res.data;
						that.getFilList(res.data);
				    },
					fail:function(error){
						uni.navigateTo({
							url: `/pages/login/login`
						})
					}});
			},
			getFilList(token){
				var that=this;
				var url='';
				if(that.current!=3){
					url = that.serverUrl2 + '/biz/api/v1/cp/kj/category/'+that.current
				}
				else{
					url = that.serverUrl2 +'/biz/api/v1/cp/cbsx'
				}
				
				uni.request({
						url: url,
						method: "GET",
						header: {
							'content-type': 'application/json',
							'Authorization': 'Bearer '+token
						},
						success: (res) => {
							if (res.data.code == 200) {
								console.log(res.data);
								that.listData=res.data.data;
							}
						},
						complete: (error) => {
							console.log(error);
						}
					})
			},
			
			
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		// align-items: center;
		background-color: #F2F2F2;
		bottom: 0;
		position: fixed;
		width: 100%;
		height: 100%;
	}
	.bannerBG {
		width: 92%;
		height: 120upx;
		background-color: #12B3F9;
		display: flex;
		padding-left: 4%;
		padding-right: 4%;
		align-items: center;
		justify-content: space-between;
		// border-radius:0upx 0upx 30upx 30upx;
		
		.active {
			background-color: #FFD10c;
			color: #433302;
			// width: 20%;
			padding: 20upx;
			text-align: center;
			border-radius: 10upx;
			font-size: $uni-font-size-base;
		}
		
		.inactive {
			background-color: #FFFFFF;
			color: #656565;
			// width: 20%;
			padding: 20upx;
			text-align: center;
			border-radius: 10upx;
			font-size: $uni-font-size-base;
		}
	}
	.listItem {
		display: flex;
		flex-direction: column;
		margin-top: 40upx;
		width: 82%;
		margin-left: 4%;
		margin-right: 4%;
		border-radius: 10upx;
		background-color: #FFFFFF;
		padding: 5%;
		
		.itemTitle {
			display: flex;
			flex-direction: row;
			flex-wrap: nowrap;
			justify-content: space-between;
			align-items: center;
		}
	}
</style>
